import baostock as bs
import pandas as pd
import sys

def load_data(stock_code, start_date, end_date, freStr, aStr):
    rs = bs.query_history_k_data(stock_code, "date,time,code,open,high,low,close,volume,amount",
    start_date=start_date,frequency=freStr,adjustflag=aStr)
    list = []
    while (rs.error_code == '0') & rs.next():
        data = rs.get_row_data()
        dic = {}
        for i in range(len(rs.fields)):
            dic[rs.fields[i]] = data[i]
        list.append(rs.get_row_data())
        print(dic)
    return list

def main(stock_code,start_date,end_date,frq,a):
    lg = bs.login()
    list = load_data(stock_code, start_date, end_date, frq, a)
    bs.logout()
    return list

if __name__ == '__main__':
    args = sys.argv[1]
    argArray = args.split(',')
    stock_code = argArray[0]
    start_date = argArray[1]
    end_date = argArray[2]
    frq = argArray[3]
    a = argArray[4]
    main(stock_code,start_date,end_date,frq,a)